package gui.client.listener;

import gui.ButtonName;
import gui.GuiCommon;
import gui.client.Client;
import gui.common.BaseClientFrame;
import gui.common.CommonListener;
import gui.common.DefaultGroupList;
import gui.common.ForumListPanel;
import gui.common.LoginDialogue;
import gui.common.MessageListPanel;
import gui.common.detail.DetailPage;
import gui.common.detail.ForumDetail;
import gui.common.detail.GroupDetail;
import gui.common.detail.MessageDetail;
import gui.common.detail.UserDetail;
import gui.common.msg.MsgType;
import gui.common.msg.SysMessage;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import client.ChatClient;

import data.Forum;
import data.Group;
import data.Message;
import data.User;

public class ClientButtonListener implements ActionListener{

	private DetailPage src=null;
	public ClientButtonListener(DetailPage source) {
		this.src=source;
	}
	public void actionPerformed(ActionEvent event) {
		Client client=Client.getInstance();
		String buttonName = event.getActionCommand();
		System.out.println(buttonName);
		if (buttonName.equals(ButtonName.LOGIN)){
        	if(client.isConnected()){
	        	
	        	LoginDialogue ld=new LoginDialogue(client);
	        	ld.setVisible(true);
        	}
        }else if(buttonName.equals(ButtonName.CREATE_NEW_ACCOUNT)){
        	if(client.isConnected()){
        		UserDetail user=new UserDetail(true,null,false);
        		user.setVisible(true);
        	}
        }else if(buttonName.equals(ButtonName.LEAVE_GROUP)){
        	CommonListener.leaveGroup(client,this);
        }else if(buttonName.equals(ButtonName.CREATE_ACCOUNT)){
        	CommonListener.createAccount(client,src);
        }else if(buttonName.equals(ButtonName.ENTER_GROUP)){
        	CommonListener.enterGroup(client,this);
        }else if(buttonName.equals(ButtonName.ENTER_FORUM)){
        	CommonListener.enterForum(client,this);
        }else if(buttonName.equals(ButtonName.LEAVE_FORUM)){
        	CommonListener.leaveForum(client,this);
        }else if(buttonName.equals(ButtonName.CREATE_NEW_GROUP)){
        	CommonListener.createGroup(client,false);
        }else if(buttonName.equals(ButtonName.CREATE_NEW_FORUM)){
        	CommonListener.createForum(client,false);
        }else if(buttonName.equals(ButtonName.CREATE_NEW_MESSAGE)){
        	CommonListener.createMeasage(client,false);
        }else if(buttonName.equals(ButtonName.CREATE_GROUP)){
        	CommonListener.createGroup(client,src);
        }else if(buttonName.equals(ButtonName.CREATE_FORUM)){
        	CommonListener.createForum(client,src,this);
        }else if(buttonName.equals(ButtonName.CREATE_MESSAGE)){
        	CommonListener.createMessage(client,src,this);
        }else if(buttonName.equals(ButtonName.START_CHAT)){
        	CommonListener.startChat(client);
        }
	}
	
}
